﻿﻿﻿﻿﻿﻿@extends('admin.Default')
@section('type')
    <!-- Data Tables -->
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/summernote/summernote-bs3.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/basic.css') }}" rel="stylesheet">
    <link href="{{ asset('myadmin/css/plugins/dropzone/dropzone.css') }}" rel="stylesheet">
    <style type="text/css">
        .ibox-content {
            float: none;
            display: block;
            margin-left: auto;
            margin-right: auto;
        }
    </style>
@stop
@section('content')




    <div class="row">
        <div class="col-lg-6">
            <div class="ibox float-e-margins">
                <div class="ibox-content col-sm-8">
                    <form class="form-horizontal m-t" id="doctorForm" action="/admin/doctor" method="post" enctype='multipart/form-data'>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">账号：</label>
                            <div class="col-sm-6">
                                <input type="text" name="username" class="form-control" placeholder="请输入账号名 位数6-15之间">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 control-label">密码：</label>
                            <div class="col-sm-6">
                                <input type="text" name="password" class="form-control"  placeholder="密码位数6-15之间且不能为空">
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-sm-3 control-label">真实姓名：</label>
                            <div class="col-sm-6 ">
                                <input type="text" name="name" class="form-control" placeholder="请输入姓名">
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">身份证号：</label>
                            <div class="col-sm-6 ">
                                <input type="text" name="idcard" class="form-control" placeholder="请输入正确的身份证号">
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 control-label">性别：</label>
                            <div class="col-sm-4">
                                <label class="radio-inline">
                                    <input type="radio" checked="" value="1"  name="sex">男</label>
                                <label class="radio-inline">
                                    <input type="radio" value="2" name="sex">女</label>
                            </div>
                        </div>
                        <div class=" form-group row">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">年龄：</label>
                                <div class="col-sm-6">
                                    <input type="text" name="age" class="form-control" placeholder="请输入年龄">
                                </div>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">联系方式：</label>
                            <div class="col-sm-6 ">
                                <input type="text" name="phone" class="form-control" placeholder="152-6674-3901">
                            </div>
                        </div>
                        <div class=" form-group row">
                            <div class="form-group">
                                <label class="col-sm-3 control-label">所在城市：</label>
                                <div class="col-sm-8">
                                    <select id='select1'>
                                        <option >--请选择--</option>

                                    </select>
                                </div>
                            </div>
                        </div>

                        <div class="form-group row">
                            <label class="col-sm-3 control-label">具体地址：</label>
                            <div class="col-sm-6">
                                <input type="text"  name="address" id="suggestId"  class="form-control" placeholder="请输入所属品牌">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 control-label">状态：</label>
                            <div class="col-sm-4">
                                <label class="radio-inline">
                                    <input type="radio"  value="1" id="optionsRadios1" name="status">上班</label>
                                <label class="radio-inline">
                                    <input type="radio" value="2" id="optionsRadios2" name="status">下班</label>
                                <label class="radio-inline">
                                    <input type="radio" value="3" checked="" id="optionsRadios3" name="status">冻结</label>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">药师简介：</label>
                            <div class="col-sm-8">
                                <textarea id="ccomment" name="summary" class="form-control" required="" aria-required="true"></textarea>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">资质名称：</label>
                            <div class="col-sm-6 ">
                                <input type="text" name="credname" class="form-control" placeholder="请输入姓名">
                            </div>
                        </div>
                        <div class="form-group row">
                            <label class="col-sm-3 control-label">资质编号：</label>
                            <div class="col-sm-6">
                                <input type="text" name="crednum" class="form-control" placeholder="123456789">
                            </div>
                        </div>
                        <div class="list list-title col-sm-12">
                            <label class="col-sm-3 control-label">药师资质：</label>
                            <img id="pic" src="{{ asset('upload/store/default.jpg') }}" width="200">
                            <input style="display: none" type="file" id="img" name="file" >
                            <button type="button" onclick="demo();"  >点击添加<br></button>
                        </div>



                        <input type='hidden' name='_token' value='{{ csrf_token() }}'>
                        <button class="btn btn-sm btn-primary pull-right m-t-n-xs" type="submit"
                        ><strong>提交</strong>
                        </button>
                        <div class="clearFix"></div>
                    </form>
                </div>
            </div>

        </div>
    </div>


@stop
@section('script')
    <!-- SUMMERNOTE -->
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote.min.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/summernote/summernote-zh-CN.js') }}"></script>
    <script src="{{ asset('myadmin/js/plugins/dropzone/dropzone.js') }}"></script>
    <script src="{{ asset('tools/form-builder/beautifyhtml.js') }}"></script>
    <!-- Jquery Validate -->
    <script src="{{ asset('myadmin/js/plugins/validate/jquery.validate.min.js') }}"></script>

    <script src="{{ asset('myadmin/js/plugins/validate/messages_zh.min.js') }}"></script>
    <script>

            @if(!empty(session('success')))
                alert('{{ session('success') }}');
            @endif

    </script>
    <script>


        $.ajax({
            url:'/admin/store/district',
            async:false,				//是否异步
            type:'post',				//请求方式
            data:{upid:0,_token: "{{ csrf_token() }}"},				//发送的数据
            dataType:'json',			//响应的数据类型
            error:function()			//失败时回调函数
            {
                alert('ajax请求失败');
            },
            success:function(data)		//成功时回调函数
            {
                //console.log(data);
                for (var i = 0; i < data.length; i++) {
                    $('#select1').append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                };
            }
        });

        $(document).on("change","select",function(){

            //先清除后面的select，再添加新的select
            $(this).nextAll("select").remove();
            //因为下面需要用到当前对象，但是是另一个函数体内，不能用$(this)
            var ob = $(this);
            var address = '';
            //判断选择的是不是默认的请选择
            if($(this).val() != '--请选择--'){
                var upid = $(this).val();
                //找到每个节点的html值
                for (var y=1;y<=$('select').length;y++){

                    //console.log($('#select'+y).length);
                    if($('#select'+y).length!=0){
                        address += $('#select'+y).find('option:selected').html();
                    }
                }
                 //alert(address);
                $('#suggestId').val(address);
                if($('#select3').length==0){
                    $.ajax({
                        url:'/admin/store/district',
                        async:false,				//是否异步
                        type:'post',				//请求方式
                        data:{upid:upid,_token: "{{ csrf_token() }}"},				//发送的数据
                        dataType:'json',			//响应的数据类型
                        error:function()			//失败时回调函数
                        {
                            alert('ajax请求失败');
                        },
                        success:function(data)		//成功时回调函数
                        {

                            //判断是否还有数据返回
                            if(data.length>0){
                                //新建一个select标签
                                var select = $("<select name="+'select['+data[0].level+"] id="+'select'+data[0].level+"><option>--请选择--</option></select>");
                                //循环给select标签添加上option
                                for (var i = 0; i < data.length; i++) {
                                    $(select).append("<option value='"+data[i].id+"'>"+data[i].name+"</option>");
                                };
                                console.log($(select));
                                //追加到前一个select后面
                                ob.after(select);
                            }
                        }
                    });
                }
            }

        });
        function demo(){
            $("#img").click();  //隐藏了input:file样式后，点击头像就可以本地上传
            $("#img").on("change",function(){
                var objUrl = getObjectURL(this.files[0]) ; //获取图片的路径，该路径不是图片在本地的路径
                if (objUrl) {
                    $("#pic").attr("src", objUrl) ; //将图片路径存入src中，显示出图片
                }
            });
        }


        //建立一個可存取到該file的url
        function getObjectURL(file) {
            var url = null ;
            if (window.createObjectURL!=undefined) { // basic
                url = window.createObjectURL(file) ;
            } else if (window.URL!=undefined) { // mozilla(firefox)
                url = window.URL.createObjectURL(file) ;
            } else if (window.webkitURL!=undefined) { // webkit or chrome
                url = window.webkitURL.createObjectURL(file) ;
            }
            return url ;
        }
    </script>
    <script>
        $(document).ready(function () {

            $("#doctorForm").validate({
                rules: {
                    name: {
                        required: true,
                    },
                    username: {
                        required: true,
                        rangelength: [6,15],
                    },
                    password: {
                        required: true,
//                        number: true,
                        rangelength: [6,15],
                    },
                    phone: {
                        required: true,
                        number: true,
                        rangelength: [11,11],
                    },
                    age: {
                        required: true,
                        number: true,
                    },
                    idcard: {
                        required: true,
                        number: true,
                        rangelength: [18,18],
                    },
                    crednum: {
                        required: true,
                        number: true,

                    },
                    address: {
                        required: true,
                    },
                    summary: {
                        required: true,
                    },
                    credname: {
                        required: true,
                    }
                }
            });
        });
    </script>



@stop
